<%--防止js乱码--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2>Hello World!</h2>
</body>
<script type="text/javascript">

    <%--将对象转成json格式数据--%>
    const obj = {
        name: '张三',
        age: 18,
        gender: '男'
    }
    const jsonStr = JSON.stringify(obj);
    console.log(jsonStr);


    <%--将json格式的数据转成对象--%>
    const jsonNewStr = '{"name":"张三","age":18,"gender":"男"}';
    const newObj = JSON.parse(jsonNewStr);
    console.log(newObj);

</script>
</html>
